package lab02.test06;

/**
 * Created by 婷婷 on 2017/10/15.
 */
public class Triangle {

    //属性：三角形的三个边，周长，面积
    private double side1;
    private double side2;
    private double side3;
    private double circumference;
    private double area;

    //Triangle类具有返回周长、面积以及修改三个边的功能
    public void setSide(double side1, double side2, double side3) {
        this.side1 = side1;
        this.side2 = side2;
        this.side3 = side3;
    }
    public void setSide1(double side1, double side2, double side3) {
        this.side1 = side1;
        this.side2 = side2;
        this.side3 = side3;
    }

    /*
    判断三条边是否构成一个三角形,满足if条件，返回true，否则返回false并输出
     */
    public boolean isTriangle() {

        if ((side1 < side2 + side3) && (side1 > Math.abs(side2 - side3))) {
            return true;
        } else {
            System.out.println("你输入的边不能构成三角形！");
            return false;
        }
    }

    //方法
    //返回三角形的周长
    public double circumference() {
        circumference = side1 + side2 + side3;
        return circumference;
    }


    //返回三角形的面积
    public double area() {
        //计算三角形的面积
        double area = Math.sqrt(circumference / 2 - (circumference / 2 - side1)
                * (circumference / 2 - side2) * (circumference / 2 - side3));
        return area;
    }
}
